home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Arsenal Files 6
/
The Arsenal Files 6 (Arsenal Computer).ISO
/
prg_casm
/
jlvesa11.zip
/
JLVESA20.ASM
< prev
next >
Wrap
Assembly Source File
|
1995-12-19
|
2KB
|
89 lines
; This file is part of JLVESA SVGA-library
;
; Copyright 1995 Johannes Lehtinen
; All rights reserved
model large,c
p386
segment jlvesa20_TEXT USE16 'CODE'
assume cs:jlvesa20_TEXT
; int JVColor_Find(JVPalette palette, JVUByte red, JVUByte green, JVUByte blue)
;
; Finds best fitting color
best_color dw ?
best_distance dd ?
proc JVColor_Find far
public JVColor_Find
push bp
mov bp,sp
push si
push di
push ds
; Load address of palette
lds si,[ss:bp+6]
cld
; Go through colors
xor bx,bx ; BX is color being handled
mov [cs:best_distance],0ffffH ; Set distance to maximum value
find_loop:
xor ecx,ecx ; ECX is distance
mov di,10 ; Offset of color value
; Go through color arguments
inner_loop:
xor eax,eax ; EAX is value of color being handled
xor edx,edx ; EDX is value of color searched
lodsb
mov dl,[ss:bp+di]
sub eax,edx ; Calculate difference
imul eax ; Difference to second power
add ecx,eax ; Add difference to second power to ECX
add di,2
cmp di,14 ; Check if values left to check
jbe short inner_loop
; Check if color is closer to wanted than previous best. If it is
; mark current color as best available.
cmp [cs:best_distance],ecx
jbe short is_not_closer
mov [cs:best_color],bx
mov [cs:best_distance],ecx
or ecx,ecx
jz short loop_end
is_not_closer:
inc bx
cmp bx,256
jb short find_loop
; Return nearest color
loop_end:
mov ax,[cs:best_color]
pop ds
pop di
pop si
pop bp
retf
endp JVColor_Find
ends
end